package server;

import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

public class MainServer {
	
	
	/**
	 * 
	 *
	 */

	public static void main(String[] args) {
		
		
		try {
			java.rmi.registry.LocateRegistry.createRegistry(1099);
			System.out.println("RMI registry ready.");
		} catch (Exception e) {
			System.out.println("Exception starting RMI registry:");
			e.printStackTrace();
		}
		
		Handler h = new Handler();
		new Thread(h).start();
		TweetParser parser = new TweetParser(h);
		new Thread(parser).start();
		h.setParser(parser);
		ConnectionManager manager = new ConnectionManager(parser);
		ClientManager client = new ClientManager(manager, h, parser);
		h.setManager(client);
        try {
            ServerInterface stub = (ServerInterface) UnicastRemoteObject.exportObject(client, 0);
            Registry registry = LocateRegistry.getRegistry();
            String name = "ClientManager";
            registry.rebind(name, stub);
            System.out.println("ClientManager bound");
        } catch (Exception e) {
            System.err.println("ClientManager exception:");
            e.printStackTrace();
        }

	}
}
